package example;
import facecat.FaceCatScript;
import facecat.topin.core.*;
import facecat.topin.xml.*;
import facecat.topin.div.*;
import facecat.topin.input.FCTextBox;

/*
* 右键菜单示例
*/
public class MenuExample extends FCUIXml implements FCTouchEventCallBack, FCMenuItemTouchEventCallBack
{
    public FCMenu m_menu;
    
     /*
     * 加载Xml
     * @param fileName 文件名
     * @param view 视图名称
     */
   public void loadXml(String fileName, FCView view)
   {
       setScript(new FaceCatScript(this));
       super.loadXml(fileName, view);
       getTabPage("TabPage").addEvent(this, FCEventID.TouchDown, this);
        m_menu = new FCMenu();
        m_menu.setVisible(false);
        m_menu.setPopup(true);
        m_menu.setSize(new FCSize(100, 200));
        getNative().addView(m_menu);
        m_menu.addEvent(this, FCEventID.MenuItemClick, this);
        for (int i = 0; i < 10; i++)
        {
            FCMenuItem menuItem = new FCMenuItem();
            menuItem.setText("菜单项");
            m_menu.addItem(menuItem);
            for (int j = 0; j < 10; j++)
            {
                FCMenuItem subMenuItem = new FCMenuItem();
                subMenuItem.setText("子菜单项");
                menuItem.addItem(subMenuItem);
                for (int z = 0; z < 10; z++)
                {
                    FCMenuItem sunMenuItem = new FCMenuItem();
                    sunMenuItem.setText("孙菜单项");
                    subMenuItem.addItem(sunMenuItem);
                }
                subMenuItem.getDropDownMenu().setSize(new FCSize(100, 200));
            }
            menuItem.getDropDownMenu().setSize(new FCSize(100, 200));
        }
   }
   
     /*
     * 点击事件
     * @param eventName 事件ID
     * @param sender 发送者
     * @param touchInfo 触摸信息
     * @param invoke 引用者
     */
    public void callTouchEvent(String eventName, Object sender, FCTouchInfo touchInfo, Object invoke)
    {
        if (touchInfo.m_secondTouch)
        {
            m_menu.setLocation(getNative().getTouchPoint());
            m_menu.show();
            getNative().invalidate();
        }
    }
    
    /*
     * 菜单点击事件
     * @param eventName 事件ID
     * @param sender 发送者
     * @param item 菜单项
     * @param touchInfo 触摸信息
     * @param invoke 引用者
     */
    public void callMenuItemTouchEvent(String eventName, Object sender, FCMenuItem item, FCTouchInfo touchInfo, Object invoke)
    {
    }
}